import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import UserService from '../service/user.service';
import R from 'libs/common/utils/R';
import CreateUserDto from '../dto/CreateUserDto';

@Controller('/user')
export default class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('/create')
  async create(@Body() createUserDto: CreateUserDto): Promise<R<any>> {
    await this.userService.createUser(createUserDto);
    return R.ok();
  }

  @Get('/getUserByEmail')
  async getUserByEmail(@Query('email') email: string): Promise<R<any>> {
    const user = await this.userService.getUserByEmail(email);
    return R.ok(user);
  }

  @Get('/getRoleKeysByUserId')
  async getRoleKeysByUserId(@Query('userId') userId: string): Promise<R<any>> {
    const roleKeys = await this.userService.getRoleKeysByUserId(userId);
    return R.ok(roleKeys);
  }
}
